package com.da.lon.wang.xlg.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.activity.WebViewActivity;
import com.da.lon.wang.xlg.adapter.OutGoodsAdapter;
import com.da.lon.wang.xlg.adapter.WaitGoosAdapter;
import com.da.lon.wang.xlg.bean.WaitGoods;
import com.da.lon.wang.xlg.bean.WaitGoodsListBean;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.http.HttpLoader;
import com.da.lon.wang.xlg.http.HttpLoader.OnWebLoadListener;
import com.da.lon.wang.xlg.pulltorefresh.library.PullToRefreshBase;
import com.da.lon.wang.xlg.pulltorefresh.library.PullToRefreshBase.Mode;
import com.da.lon.wang.xlg.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.da.lon.wang.xlg.pulltorefresh.library.PullToRefreshListView;
import com.da.lon.wang.xlg.util.CustomListener;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.XLGDataUtils;
import com.umeng.analytics.MobclickAgent;
import com.zxing.android.CaptureActivity;

import net.tsz.afinal.http.AjaxParams;

import java.util.ArrayList;
import java.util.List;

public class GroupBuyFragment extends BaseFragment implements
        OnRefreshListener2<ListView>, OnCheckedChangeListener {
    private HttpLoader<WaitGoodsListBean> loader;
    private PullToRefreshListView listView;
    private PullToRefreshListView listView2;
    private RadioGroup sellerGroup;
    private int page = 1;
    private int size = 10;
    private int state = 0;
    private List<WaitGoods> list = new ArrayList<WaitGoods>();
    private List<WaitGoods> list2 = new ArrayList<WaitGoods>();
    private View view;
    private CustomListener listener = new CustomListener() {

        @Override
        public void onCustomListener(int obj0, final Object obj1,
                                     final int position) {
            final AjaxParams params = new AjaxParams();
            final String merchant_id = PreferenceUtils.getInstance()
                    .getSettingStr(PreferencesConfig.MERCHANT_ID, "");
            switch (obj0) {
                case 0:// 抢单
                    try {
                        if (obj1 != null) {
                            WaitGoods waitGoods1 = (WaitGoods) obj1;

                            loader = new HttpLoader<WaitGoodsListBean>(
                                    getActivity(),
                                    "http://xm.ocoffee.cn/Mobile?service=Order_updateMyGrabOrder",
                                    WaitGoodsListBean.class, 60 * 1000);
                            if (waitGoods1.getOrder_product() != null
                                    && waitGoods1.getOrder_product().size() > 0
                                    && waitGoods1.getOrder_product().get(0) != null) {
                                params.put("order_id", waitGoods1
                                        .getOrder_product().get(0).getOrders_id());
                            }
                            params.put("type", "1");// 抢单是1 取消抢单是0
                            params.put("merchant_id", merchant_id);// 商户id

                            params.put("token", XLGDataUtils.encrypt2MD5("Order"
                                    + "2015#$%" + "updateMyGrabOrder"));
                            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                @Override
                                public void OnStart() {
                                    // TODO Auto-generated method stub
                                    showDialog();
                                }

                                @Override
                                public void OnError(String error) {
                                    // TODO Auto-generated method stub
                                    dismissDialog();
                                }

                                @Override
                                public void onSuccess(WaitGoodsListBean t) {
                                    // TODO Auto-generated method stub
                                    dismissDialog();
                                    if (t != null) {
                                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                        if (bean != null
                                                && bean.getCode().equals("000000")) {
                                            Toast.makeText(getActivity(), "抢单成功",
                                                    Toast.LENGTH_LONG).show();

                                            loader = new HttpLoader<WaitGoodsListBean>(
                                                    getActivity(),
                                                    "http://xm.ocoffee.cn/Mobile?service=Order_grabOrderList",
                                                    WaitGoodsListBean.class,
                                                    60 * 1000);
                                            AjaxParams params = new AjaxParams();
                                            params.put("page", page + "");
                                            params.put("size", size + "");

                                            params.put(
                                                    "token",
                                                    XLGDataUtils
                                                            .encrypt2MD5("Order"
                                                                    + "2015#$%"
                                                                    + "grabOrderList"));

                                            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                                @Override
                                                public void OnStart() {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    showDialog();
                                                }

                                                @Override
                                                public void OnError(String error) {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    dismissDialog();
                                                }

                                                @Override
                                                public void onSuccess(
                                                        WaitGoodsListBean t) {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    dismissDialog();
                                                    if (t != null) {
                                                        WaitGoodsListBean bean = (WaitGoodsListBean) t;

                                                        if (bean != null
                                                                && bean.getCode()
                                                                .equals("000000")) {

                                                            list = t.getResult();
                                                            if (list != null
                                                                    && listView != null
                                                                    && listView
                                                                    .getRefreshableView() != null
                                                                    && listener != null) {
                                                                listView.getRefreshableView()
                                                                        .setAdapter(
                                                                                new WaitGoosAdapter(
                                                                                        list,
                                                                                        getActivity(),
                                                                                        listener));
                                                            }
                                                        }
                                                    }
                                                }
                                            });
                                            loader.loadData(params);
                                        } else {
                                            Toast.makeText(getActivity(),
                                                    bean.getMessage(),
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }
                                }
                            });
                            loader.loadData(params);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 1:// 改派订单
                    try {
                        if (obj1 != null) {
                            WaitGoods waitGoods2 = (WaitGoods) obj1;

                            loader = new HttpLoader<WaitGoodsListBean>(
                                    getActivity(),
                                    "http://xm.ocoffee.cn/Mobile?service=Order_updateMyGrabOrder",
                                    WaitGoodsListBean.class, 60 * 1000);
                            if (waitGoods2 != null
                                    && waitGoods2.getOrder_product() != null
                                    && waitGoods2.getOrder_product().size() > 0
                                    && waitGoods2.getOrder_product().get(0) != null
                                    && waitGoods2.getOrder_product().get(0)
                                    .getOrders_id() != null) {
                                params.put("order_id", waitGoods2
                                        .getOrder_product().get(0).getOrders_id());
                            }
                            params.put("type", "0");// 抢单是1 取消抢单是0
                            params.put("merchant_id", merchant_id);// 商户id

                            params.put("token", XLGDataUtils.encrypt2MD5("Order"
                                    + "2015#$%" + "updateMyGrabOrder"));
                            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                @Override
                                public void OnStart() {
                                    // TODO Auto-generated method stub
                                    showDialog();
                                }

                                @Override
                                public void OnError(String error) {
                                    // TODO Auto-generated method stub
                                    dismissDialog();
                                }

                                @Override
                                public void onSuccess(WaitGoodsListBean t) {
                                    // TODO Auto-generated method stub
                                    dismissDialog();
                                    if (t != null) {
                                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                        if (bean != null
                                                && bean.getCode().equals("000000")) {
                                            Toast.makeText(getActivity(), "改派订单成功",
                                                    Toast.LENGTH_LONG).show();

                                            loader = new HttpLoader<WaitGoodsListBean>(
                                                    getActivity(),
                                                    "http://xm.ocoffee.cn/Mobile?service=Order_myGrabOrderList",
                                                    WaitGoodsListBean.class,
                                                    60 * 1000);
                                            AjaxParams params1 = new AjaxParams();
                                            params1.put("page", page + "");
                                            params1.put("size", size + "");
                                            String merchant_id = PreferenceUtils
                                                    .getInstance()
                                                    .getSettingStr(
                                                            PreferencesConfig.MERCHANT_ID,
                                                            "");
                                            params1.put("merchant_id", merchant_id);// 商户id

                                            params1.put(
                                                    "token",
                                                    XLGDataUtils
                                                            .encrypt2MD5("Order"
                                                                    + "2015#$%"
                                                                    + "myGrabOrderList"));
                                            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                                @Override
                                                public void OnStart() {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    showDialog();
                                                }

                                                @Override
                                                public void OnError(String error) {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    dismissDialog();
                                                }

                                                @Override
                                                public void onSuccess(
                                                        WaitGoodsListBean t) {
                                                    // TODO Auto-generated method
                                                    // stub
                                                    dismissDialog();
                                                    if (t != null) {
                                                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                                        if (bean != null
                                                                && bean.getCode()
                                                                .equals("000000")) {

                                                            list2 = t.getResult();
                                                            if (list2 != null
                                                                    && listView2 != null
                                                                    && listView2
                                                                    .getRefreshableView() != null
                                                                    && listener != null) {
                                                                listView2
                                                                        .getRefreshableView()
                                                                        .setAdapter(
                                                                                new OutGoodsAdapter(
                                                                                        list2,
                                                                                        getActivity(),
                                                                                        listener));
                                                            }
                                                        }
                                                    }
                                                }
                                            });
                                            loader.loadData(params1);
                                        } else {
                                            Toast.makeText(getActivity(),
                                                    bean.getMessage(),
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }
                                }
                            });
                            loader.loadData(params);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 2:// 手工发货
                    try {
                        if (obj1 != null) {
                            WaitGoods waitGoods3 = (WaitGoods) obj1;

                            Intent intent1 = new Intent(getActivity(),
                                    WebViewActivity.class);

                            Bundle bundle1 = new Bundle();
                            bundle1.putString("orders_id", waitGoods3
                                    .getOrder_product().get(0).getOrders_id());
                            bundle1.putInt("flag", 1600);
                            intent1.putExtras(bundle1);
                            startActivity(intent1);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 3:// 扫码发货
                    try {
                        if (obj1 != null) {
                            WaitGoods waitGoods5 = (WaitGoods) obj1;

                            Intent intent2 = new Intent(getActivity(),
                                    CaptureActivity.class);

                            Bundle bundle2 = new Bundle();
                            bundle2.putString("orders_id", waitGoods5
                                    .getOrder_product().get(0).getOrders_id());
                            intent2.putExtras(bundle2);
                            startActivity(intent2);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case 4:// 物流信息
                    try {
                        if (obj1 != null) {
                            WaitGoods waitGoods4 = (WaitGoods) obj1;

                            Intent intent3 = new Intent(getActivity(),
                                    WebViewActivity.class);

                            Bundle bundle3 = new Bundle();
                            bundle3.putString("orders_id", waitGoods4
                                    .getOrder_product().get(0).getOrders_id());
                            bundle3.putInt("flag", 1400);
                            intent3.putExtras(bundle3);
                            startActivity(intent3);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;

                case 5:// 延长发货
                    try {
                        final Dialog dialog = new Dialog(getActivity(),
                                R.style.ocoffee_dialog);
                        View dialogView = LayoutInflater.from(getActivity())
                                .inflate(R.layout.ouka_delay_dialog, null);
                        dialog.setContentView(dialogView);
                        dialog.show();

                        ImageButton cancelButton = (ImageButton) dialogView
                                .findViewById(R.id.cancelButton);
                        ImageButton delayButton = (ImageButton) dialogView
                                .findViewById(R.id.delayButton);

                        cancelButton.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View arg0) {
                                dialog.dismiss();
                            }
                        });

                        delayButton.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View arg0) {
                                if (obj1 != null) {
                                    WaitGoods waitGoods = (WaitGoods) obj1;

                                    loader = new HttpLoader<WaitGoodsListBean>(
                                            getActivity(),
                                            "http://xm.ocoffee.cn/Mobile?service=Order_timedelay",
                                            WaitGoodsListBean.class, 60 * 1000);
                                    if (waitGoods != null
                                            && waitGoods.getOrder_product() != null
                                            && waitGoods.getOrder_product().size() > 0
                                            && waitGoods.getOrder_product().get(0) != null
                                            && waitGoods.getOrder_product().get(0)
                                            .getOrders_id() != null) {
                                        params.put("order_id", waitGoods
                                                .getOrder_product().get(0)
                                                .getOrders_id());
                                    }
                                    params.put("merchant_id", merchant_id);// 商户id

                                    params.put("token", XLGDataUtils
                                            .encrypt2MD5("Order" + "2015#$%"
                                                    + "timedelay"));
                                    loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                        @Override
                                        public void OnStart() {
                                            // TODO Auto-generated method stub
                                            showDialog();
                                        }

                                        @Override
                                        public void OnError(String error) {
                                            // TODO Auto-generated method stub
                                            dismissDialog();
                                        }

                                        @Override
                                        public void onSuccess(WaitGoodsListBean t) {
                                            // TODO Auto-generated method stub
                                            dismissDialog();
                                            if (t != null) {
                                                WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                                if (bean != null
                                                        && bean.getCode().equals(
                                                        "000000")) {
                                                    Toast.makeText(getActivity(),
                                                            "延长发货成功",
                                                            Toast.LENGTH_LONG)
                                                            .show();

                                                    loader = new HttpLoader<WaitGoodsListBean>(
                                                            getActivity(),
                                                            "http://xm.ocoffee.cn/Mobile?service=Order_myGrabOrderList",
                                                            WaitGoodsListBean.class,
                                                            60 * 1000);
                                                    AjaxParams params1 = new AjaxParams();
                                                    params1.put("page", page + "");
                                                    params1.put("size", size + "");
                                                    String merchant_id = PreferenceUtils
                                                            .getInstance()
                                                            .getSettingStr(
                                                                    PreferencesConfig.MERCHANT_ID,
                                                                    "");
                                                    params1.put("merchant_id",
                                                            merchant_id);// 商户id

                                                    params1.put(
                                                            "token",
                                                            XLGDataUtils
                                                                    .encrypt2MD5("Order"
                                                                            + "2015#$%"
                                                                            + "myGrabOrderList"));
                                                    loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                                                        @Override
                                                        public void OnStart() {
                                                            showDialog();
                                                        }

                                                        @Override
                                                        public void OnError(
                                                                String error) {
                                                            dismissDialog();
                                                        }

                                                        @Override
                                                        public void onSuccess(
                                                                WaitGoodsListBean t) {
                                                            dismissDialog();
                                                            if (t != null) {
                                                                WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                                                if (bean != null
                                                                        && bean.getCode()
                                                                        .equals("000000")) {

                                                                    list2 = t
                                                                            .getResult();
                                                                    if (list2 != null
                                                                            && listView2 != null
                                                                            && listView2
                                                                            .getRefreshableView() != null
                                                                            && listener != null) {
                                                                        listView2
                                                                                .getRefreshableView()
                                                                                .setAdapter(
                                                                                        new OutGoodsAdapter(
                                                                                                list2,
                                                                                                getActivity(),
                                                                                                listener));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    });
                                                    loader.loadData(params1);

                                                } else {
                                                    Toast.makeText(getActivity(),
                                                            bean.getMessage(),
                                                            Toast.LENGTH_LONG)
                                                            .show();
                                                }
                                            }
                                        }
                                    });
                                    loader.loadData(params);

                                    dialog.dismiss();
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
            }
        }
    };

    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("GroupBuyFragment");
        MobclickAgent.onResume(getActivity());
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("GroupBuyFragment");
        MobclickAgent.onPause(getActivity());
    }

    @Override
    protected View inflateView(LayoutInflater inflater, ViewGroup var2) {
        // TODO Auto-generated method stub
        view = inflater.inflate(R.layout.ouka_buyer_groupbuy_fragment, null);
        return view;
    }

    @Override
    protected void initView() {
        // TODO Auto-generated method stub
        initView(view);

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    private void initView(View view) {
        // TODO Auto-generated method stub

        sellerGroup = (RadioGroup) view.findViewById(R.id.buyer_home_rg1);
        sellerGroup.setOnCheckedChangeListener(this);
        sellerGroup.setBackgroundResource(R.drawable.ouka_home_buyer_cheked1);

        listView = (PullToRefreshListView) view
                .findViewById(R.id.ouka_sell_listview);
        listView2 = (PullToRefreshListView) view
                .findViewById(R.id.ouka_sell2_listview);
        listView.setMode(Mode.BOTH);
        listView.setOnRefreshListener(this);
        listView2.setMode(Mode.BOTH);
        listView2.setOnRefreshListener(this);

        listView.getRefreshableView().setOnItemClickListener(
                new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        // TODO Auto-generated method stub
                        WaitGoods bean = (WaitGoods) parent.getAdapter()
                                .getItem(position);

                        Intent intent = new Intent(getActivity(),
                                WebViewActivity.class);

                        Bundle bundle = new Bundle();
                        bundle.putString("merger_sn", bean.getMerger_sn());
                        bundle.putInt("flag", 1300);
                        intent.putExtras(bundle);

                        startActivity(intent);
                    }
                });

        listView2.getRefreshableView().setOnItemClickListener(
                new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        // TODO Auto-generated method stub
                        WaitGoods bean = (WaitGoods) parent.getAdapter()
                                .getItem(position);

                        Intent intent = new Intent(getActivity(),
                                WebViewActivity.class);

                        Bundle bundle = new Bundle();
                        bundle.putString("merger_sn", bean.getMerger_sn());
                        bundle.putInt("flag", 1300);
                        intent.putExtras(bundle);

                        startActivity(intent);
                    }
                });

        loader = new HttpLoader<WaitGoodsListBean>(getActivity(),
                "http://oka.hhecz.com/Mobile?service=Order_grabOrderList",
                WaitGoodsListBean.class, 60 * 1000);
        AjaxParams params = new AjaxParams();
        params.put("page", page + "");
        params.put("size", size + "");

        params.put("token", XLGDataUtils.encrypt2MD5("Order" + "2015#$%"
                + "grabOrderList"));

        loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

            @Override
            public void OnStart() {
                // TODO Auto-generated method stub
                showDialog();
            }

            @Override
            public void OnError(String error) {
                // TODO Auto-generated method stub
                dismissDialog();
            }

            @Override
            public void onSuccess(WaitGoodsListBean t) {
                // TODO Auto-generated method stub
                dismissDialog();

                WaitGoodsListBean bean = (WaitGoodsListBean) t;

                if (t != null && bean.getCode().equals("000000")) {
                    try {
                        list = t.getResult();
                        if (listView != null
                                && listView.getRefreshableView() != null
                                && list != null && listener != null) {
                            listView.getRefreshableView().setAdapter(
                                    new WaitGoosAdapter(list, getActivity(),
                                            listener));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        loader.loadData(params);

    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
        // TODO Auto-generated method stub
        try {
            page = 1;

            loader = new HttpLoader<WaitGoodsListBean>(getActivity(),
                    "http://oka.hhecz.com/Mobile?service=Order_grabOrderList",
                    WaitGoodsListBean.class, 60 * 1000);
            AjaxParams params = new AjaxParams();
            params.put("page", page + "");
            params.put("size", size + "");

            params.put("token", XLGDataUtils.encrypt2MD5("Order" + "2015#$%"
                    + "grabOrderList"));
            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                @Override
                public void OnStart() {
                    // TODO Auto-generated method stub
                    showDialog();
                }

                @Override
                public void OnError(String error) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView != null) {
                                listView.onRefreshComplete();
                            }
                        }
                    });
                }

                @Override
                public void onSuccess(WaitGoodsListBean t) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    try {
                        new Handler().post(new Runnable() {

                            @Override
                            public void run() {
                                if (listView != null) {
                                    listView.onRefreshComplete();
                                }
                            }
                        });

                        if (t != null) {
                            WaitGoodsListBean bean = (WaitGoodsListBean) t;
                            if (bean != null && bean.getCode().equals("000000")
                                    && list != null) {
                                list.clear();
                                list = t.getResult();
                                if (listView != null
                                        && listView.getRefreshableView() != null
                                        && list != null && listener != null) {
                                    listView.getRefreshableView().setAdapter(
                                            new WaitGoosAdapter(list,
                                                    getActivity(), listener));
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            loader.loadData(params);

            loader = new HttpLoader<WaitGoodsListBean>(
                    getActivity(),
                    "http://xm.ocoffee.cn/Mobile?service=Order_myGrabOrderList",
                    WaitGoodsListBean.class, 60 * 1000);
            AjaxParams params1 = new AjaxParams();
            params1.put("page", page + "");
            params1.put("size", size + "");
            String merchant_id = PreferenceUtils.getInstance().getSettingStr(
                    PreferencesConfig.MERCHANT_ID, "");
            params1.put("merchant_id", merchant_id);// 商户id

            params1.put("token", XLGDataUtils.encrypt2MD5("Order" + "2015#$%"
                    + "myGrabOrderList"));
            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                @Override
                public void OnStart() {
                    // TODO Auto-generated method stub
                    showDialog();
                }

                @Override
                public void OnError(String error) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView2 != null) {
                                listView2.onRefreshComplete();
                            }
                        }
                    });
                }

                @Override
                public void onSuccess(WaitGoodsListBean t) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView2 != null) {
                                listView2.onRefreshComplete();
                            }
                        }
                    });
                    if (t != null) {
                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                        if (bean != null && bean.getCode().equals("000000")
                                && list2 != null) {
                            list2.clear();
                            list2 = t.getResult();
                            if (listView2 != null
                                    && listView2.getRefreshableView() != null
                                    && list2 != null && listener != null) {
                                listView2.getRefreshableView().setAdapter(
                                        new OutGoodsAdapter(list2,
                                                getActivity(), listener));
                            }
                        }
                    }
                }
            });
            loader.loadData(params1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
        // TODO Auto-generated method stub
        try {
            page++;

            loader = new HttpLoader<WaitGoodsListBean>(getActivity(),
                    "http://xm.ocoffee.cn/Mobile?service=Order_grabOrderList",
                    WaitGoodsListBean.class, 60 * 1000);
            AjaxParams params = new AjaxParams();
            params.put("page", page + "");
            params.put("size", size + "");

            params.put("token", XLGDataUtils.encrypt2MD5("Order" + "2015#$%"
                    + "grabOrderList"));
            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                @Override
                public void OnStart() {
                    // TODO Auto-generated method stub
                    showDialog();
                }

                @Override
                public void OnError(String error) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView != null) {
                                listView.onRefreshComplete();
                            }
                        }
                    });
                }

                @Override
                public void onSuccess(WaitGoodsListBean t) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView != null) {
                                listView.onRefreshComplete();
                            }
                        }
                    });
                    if (t != null) {
                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                        if (bean != null && bean.getCode().equals("000000")) {

                            if (t.getResult() == null && list != null
                                    && listener != null) {
                                WaitGoosAdapter adapter = new WaitGoosAdapter(
                                        list, getActivity(), listener);
                                adapter.notifyDataSetChanged();
                            } else {
                                list = t.getResult();
                                if (list != null && listener != null) {
                                    WaitGoosAdapter adapter = new WaitGoosAdapter(
                                            list, getActivity(), listener);
                                    adapter.notifyDataSetChanged();
                                }
                            }
                        }
                    }
                }
            });
            loader.loadData(params);

            loader = new HttpLoader<WaitGoodsListBean>(
                    getActivity(),
                    "http://xm.ocoffee.cn/Mobile?service=Order_myGrabOrderList",
                    WaitGoodsListBean.class, 60 * 1000);
            AjaxParams params1 = new AjaxParams();
            params1.put("page", page + "");
            params1.put("size", size + "");
            String merchant_id = PreferenceUtils.getInstance().getSettingStr(
                    PreferencesConfig.MERCHANT_ID, "");
            params1.put("merchant_id", merchant_id);// 商户id

            params1.put("token", XLGDataUtils.encrypt2MD5("Order" + "2015#$%"
                    + "myGrabOrderList"));
            loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                @Override
                public void OnStart() {
                    // TODO Auto-generated method stub
                    showDialog();
                }

                @Override
                public void OnError(String error) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView2 != null) {
                                listView2.onRefreshComplete();
                            }
                        }
                    });
                }

                @Override
                public void onSuccess(WaitGoodsListBean t) {
                    // TODO Auto-generated method stub
                    dismissDialog();
                    new Handler().post(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            if (listView2 != null) {
                                listView2.onRefreshComplete();
                            }
                        }
                    });
                    if (t != null) {
                        WaitGoodsListBean bean = (WaitGoodsListBean) t;
                        if (bean != null && bean.getCode().equals("000000")) {

                            if (t.getResult() == null && list2 != null
                                    && listener != null) {
                                OutGoodsAdapter adapter = new OutGoodsAdapter(
                                        list2, getActivity(), listener);
                                adapter.notifyDataSetChanged();
                            } else {
                                list2 = t.getResult();
                                if (list2 != null && listener != null) {
                                    OutGoodsAdapter adapter = new OutGoodsAdapter(
                                            list2, getActivity(), listener);
                                    adapter.notifyDataSetChanged();
                                }
                            }
                        }
                    }
                }
            });
            loader.loadData(params1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // TODO Auto-generated method stub
        switch (checkedId) {
            case R.id.single_sale1:
                try {
                    state = 0;
                    page = 1;

                    listView.setVisibility(View.VISIBLE);
                    listView.setPadding(0, 0, 0, 0);
                    listView2.setVisibility(View.GONE);

                    loader = new HttpLoader<WaitGoodsListBean>(
                            getActivity(),
                            "http://oka.hhecz.com/Mobile?service=Order_grabOrderList",
                            WaitGoodsListBean.class, 60 * 1000);
                    AjaxParams params = new AjaxParams();
                    params.put("page", page + "");

                    params.put("token", XLGDataUtils.encrypt2MD5("Order"
                            + "2015#$%" + "grabOrderList"));
                    loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                        @Override
                        public void OnStart() {
                            // TODO Auto-generated method stub
                            showDialog();
                        }

                        @Override
                        public void OnError(String error) {
                            // TODO Auto-generated method stub
                            dismissDialog();
                        }

                        @Override
                        public void onSuccess(WaitGoodsListBean t) {
                            // TODO Auto-generated method stub
                            dismissDialog();
                            if (t != null) {
                                WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                if (bean != null && bean.getCode().equals("000000")) {
                                    list = t.getResult();
                                    if (listView != null
                                            && listView.getRefreshableView() != null
                                            && list != null && listener != null) {
                                        listView.getRefreshableView().setAdapter(
                                                new WaitGoosAdapter(list,
                                                        getActivity(), listener));
                                    }
                                }
                            }
                        }
                    });
                    loader.loadData(params);

                    sellerGroup
                            .setBackgroundResource(R.drawable.ouka_home_buyer_cheked1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;

            case R.id.group_buy1:
                try {
                    state = 1;
                    page = 1;

                    listView.setVisibility(View.GONE);
                    listView2.setVisibility(View.VISIBLE);
                    listView2.setPadding(0, 0, 0, 0);

                    loader = new HttpLoader<WaitGoodsListBean>(
                            getActivity(),
                            "http://oka.hhecz.com/Mobile?service=Order_myGrabOrderList",
                            WaitGoodsListBean.class, 60 * 1000);
                    AjaxParams params1 = new AjaxParams();
                    params1.put("page", page + "");
                    params1.put("size", size + "");
                    String merchant_id = PreferenceUtils.getInstance()
                            .getSettingStr(PreferencesConfig.MERCHANT_ID, "");
                    params1.put("merchant_id", merchant_id);// 商户id

                    params1.put("token", XLGDataUtils.encrypt2MD5("Order"
                            + "2015#$%" + "myGrabOrderList"));
                    loader.setManagerListener(new OnWebLoadListener<WaitGoodsListBean>() {

                        @Override
                        public void OnStart() {
                            // TODO Auto-generated method stub
                            showDialog();
                        }

                        @Override
                        public void OnError(String error) {
                            // TODO Auto-generated method stub
                            dismissDialog();
                        }

                        @Override
                        public void onSuccess(WaitGoodsListBean t) {
                            // TODO Auto-generated method stub
                            dismissDialog();
                            if (t != null) {
                                WaitGoodsListBean bean = (WaitGoodsListBean) t;
                                if (bean != null && bean.getCode().equals("000000")) {

                                    list2 = t.getResult();
                                    if (listView2 != null
                                            && listView2.getRefreshableView() != null
                                            && list2 != null && listener != null) {
                                        listView2.getRefreshableView().setAdapter(
                                                new OutGoodsAdapter(list2,
                                                        getActivity(), listener));
                                    }
                                }
                            }
                        }
                    });
                    loader.loadData(params1);

                    sellerGroup
                            .setBackgroundResource(R.drawable.ouka_home_buyer_checked2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;

            default:
                break;
        }
    }

    @Override
    protected void RefreshData() {
        // TODO Auto-generated method stub

    }

}
